<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
    <title>@yield('title', '标题未设置') - {{Config::get('app.name')}}</title>
    <meta charset="utf-8">
    <meta name="keywords" content="@yield('keywords')">
    <meta http-equiv="Access-Control-Allow-Origin" content="*" />
    <meta name="description" content="@yield('description')">
    {{-- <link href="/assets/logo/ico.png" rel="shortcut icon"/> --}}
    <meta name="viewport" content="width=device-width, initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <!-- Styles -->
    <link rel="stylesheet" type="text/css" href="/assets/common/css/bootstrap/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/assets/common/css/fontawesome-free-5.11.2-web/css/all.min.css">
    @stack('page-css')
    <link rel="stylesheet" type="text/css" href="/assets/mobile/css/style.css?v02">
</head>
<body id="app" class="{{ route_class() }}-page">
    @yield('content')

    {{-- 全站默认js加载 --}}
    <script src="/assets/common/js/jquery/jquery-3.4.1.min.js" type="text/javascript"></script>
    <script src="//res.wx.qq.com/open/js/jweixin-1.4.0.js" type="text/javascript" charset="utf-8"></script>
    <script src="/assets/common/js/bootstrap/popper.min.js" type="text/javascript"></script>
    <script src="/assets/common/js/bootstrap/bootstrap.min.js" type="text/javascript"></script>
    <script src="/assets/common/js/layer_mobile/layer.js" type="text/javascript"></script>
    <script type="text/javascript" charset="utf-8">
    $(document).ready(function() {
        function login() {
            window.location.href = '{{ route('user.create') }}';
        }

        //获取pid(推广员)
        function getQueryVariable(variable)
        {
           var query = window.location.search.substring(1);
           var vars = query.split("&");
           for (var i=0;i<vars.length;i++) {
                   var pair = vars[i].split("=");
                   if(pair[0] == variable){return pair[1];}
           }
           return(false);
        }

        if(getQueryVariable("pid") >= 1) {
            localStorage.setItem("promote_user_id", getQueryVariable("pid"));
        }

        // ajax全局设置
        $.ajaxSetup({
            headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
            error: function (xhr, text, msg) {
                // 如果返回码是 401 代表没登录
                if (xhr.status  === 401) {
                    login();
                }
                if (xhr.status  === 403) {
                    $('#waitForPost').modal('hide');
                    layer.open({
                        content: '权限不足'
                        ,skin: 'msg'
                        ,time: 3 //2秒后自动关闭
                    });
                }
                if (xhr.status  === 500) {
                    $('#waitForPost').modal('hide');
                    layer.open({
                        content: '服务器未响应，请稍后再试'
                        ,skin: 'msg'
                        ,time: 3 //2秒后自动关闭
                    });
                    $('.alert-danger').show().find('span').text('服务器未响应，请稍后再试');
                    $('.alert-danger').fadeOut(6000);
                }
            },
        });

        //本地环境不调用
        @if(config('app.env') !== 'local')

        function isWeiXin(){
            var ua = window.navigator.userAgent.toLowerCase();
            if(ua.match(/MicroMessenger/i) == 'micromessenger'){
                return true;
            }else{
                return false;
            }
        }

        //如果是微信浏览器
        if(isWeiXin()){
            //如果已经手机登录
            @if(Auth::check())
                //如果没有绑定微信
                @if(!Auth::user()->wx_open_id)
                    window.location.href = '{{ route('wx.login') }}';
                @endif
            @endif
        }

        if($('.weixin-share').attr('src') == null || $('.weixin-share').attr('src') == "https://" + window.location.host + "/uploads/") {
            var wxShareLogo = 'https://' + window.location.host + "/assets/common/images/logo.png";
        } else {
            var wxShareLogo = $('.weixin-share').attr('src');
        }
        wx.config(<?php echo \EasyWeChat::OfficialAccount()->jssdk->buildConfig(array('updateAppMessageShareData', 'updateTimelineShareData'), false) ?>);
        wx.ready(function () {   //需在用户可能点击分享按钮前就先调用
            wx.updateAppMessageShareData({
                title: $(document).attr("title"), // 分享标题
                desc: $('meta[name="description"]').attr('content'), // 分享描述
                link: window.location.href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                imgUrl: wxShareLogo, // 分享图标
            }, function (res) {
                console.log(111)
            });
            wx.updateTimelineShareData({
                title: $(document).attr("title"), // 分享标题
                link: window.location.href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                imgUrl: wxShareLogo, // 分享图标
            }, function (res) {
                console.log(222)
            });
        });
        @endif

        //客服弹窗
        $('.kf_open').click(function() {
            $('#kfQrcode').modal('show');
        })
    })
    </script>
    @stack('page-js')
</body>
</html>
